home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / src / ConfigFileSrc.lha / ConfigFileSrc12 / RexxLibrary / Funcs / Read&Write.c < prev    next >
Encoding:
Text File  |  1997-10-02  |  3.5 KB  |  132 lines

  1. /*
  2. **        $PROJECT: RexxConfigFile.library
  3. **        $FILE: Read.c
  4. **        $DESCRIPTION: rxcf_Read() and rxcf_Write() functions
  5. **
  6. **        (C) Copyright 1997 Marcel Karas
  7. **             All Rights Reserved.
  8. */
  9.  
  10. IMPORT struct Library *CFBase;
  11.  
  12. /****** rexxconfigfile.library/cf_Read ***************************************
  13. *
  14. *   NAME
  15. *        cf_Read -- Read a CF file.
  16. *
  17. *   SYNOPSIS
  18. *        Result = cf_Read(Header)
  19. *
  20. *        BOOL cf_Read(HEADER/N/A)
  21. *
  22. *   FUNCTION
  23. *        This function clears all nodes and read the CF file new. The
  24. *        HFLG_CHANGED flag in Header will be clear.
  25. *
  26. *   INPUTS
  27. *        Header - The Header of the file.
  28. *
  29. *   RESULT
  30. *        Result - TRUE for success or in case of FALSE return, the RC var
  31. *                 can be read to obtain more.
  32. *
  33. *        RC (rexx variable) - contains an error string.
  34. *
  35. *                 RERR_UNKOWN       - Unkown failure.
  36. *                 RERR_BUFFER_MEM   - No memory for buffer.
  37. *                 RERR_READ_FILE    - Couldn't read the file.
  38. *                 RERR_FORMAT       - File has an error in the format
  39. *                                     structure.
  40. *                 RERR_UNKOWN_ITYPE - An unkown item type was found.
  41. *
  42. *   SEE ALSO
  43. *        cf_Open(), cf_Close(), cf_Write()
  44. *
  45. ******************************************************************************
  46. *
  47. */
  48.  
  49. UWORD rxcf_Read ( RX_FUNC_ARGS, CFHeader * Header )
  50. {
  51.     ULONG    Error;
  52.  
  53.     if ( cf_Read ((CFHeader *)Header, &Error) )
  54.             *ResStr = SetRC_TRUE ();
  55.     else    SetErrVar (RxMsg, ERRFUNC_READ, Error);
  56.  
  57.     return (RC_OK);
  58. }
  59.  
  60. /****** rexxconfigfile.library/cf_Write **************************************
  61. *
  62. *   NAME
  63. *        cf_Write -- Write a CF file new.
  64. *
  65. *   SYNOPSIS
  66. *        Result = cf_Write(Header [,WriteMode])
  67. *
  68. *        BOOL cf_Write(HEADER/N/A,WMODE,FLAGS)
  69. *
  70. *   FUNCTION
  71. *        This function writes the CF file new. Note is the HFLG_CHANGED
  72. *        flag in Header flags not set the file will be not writes new.
  73. *
  74. *   INPUTS
  75. *        Header - The Header of the file to write.
  76. *        WMode - Write modes:
  77. *
  78. *                WMODE_DEFAULT -- Writes the file in default format
  79. *                                 from Header.
  80. *                WMODE_ASCII   -- Writes the file in ascii format.
  81. *                WMODE_SHORT   -- Writes the file in short format.
  82. *
  83. *        Flags - Flags:
  84. *
  85. *                WFLG_WRITE_ALWAYS -- cf_Write() checks not if the
  86. *                                     HFLG_CHANGED flag set and
  87. *                                     writes always the file.
  88. *
  89. *   RESULT
  90. *        Result - TRUE for success or in case of FALSE return, the RC var
  91. *                 can be read to obtain more.
  92. *
  93. *        RC (rexx variable) - contains an error string.
  94. *
  95. *                 WERR_UNKOWN        - Unkown failure.
  96. *                 WERR_ALLOC_WBUFFER - No memory for WriteBuffer.
  97. *
  98. *   SEE ALSO
  99. *        cf_Open(), cf_Close(), cf_Read()
  100. *
  101. ******************************************************************************
  102. *
  103. */
  104.  
  105. UWORD rxcf_Write ( RX_FUNC_ARGS, CFHeader * Header )
  106. {
  107.     ULONG    Error;
  108.     UBYTE    Mode = CF_WMODE_DEFAULT;
  109.  
  110.     if ( IsValidArg (RxMsg, 2) )
  111.     {
  112.         if ( !StrCmp (RXARG2, "WMODE_ASCII") )
  113.             Mode = CF_WMODE_ASCII;
  114.         else if ( !StrCmp (RXARG2, "WMODE_SHORT") )
  115.             Mode = CF_WMODE_SHORT;
  116.         else    return (RXERR_INVALID_ARG);
  117.     }
  118.  
  119.     if ( IsValidArg (RxMsg, 3) )
  120.     {
  121.         if ( !StrCmp (RXARG3, "WFLG_WRITE_ALWAYS") )
  122.             Mode |= CF_WFLG_WRITE_ALWAYS;
  123.         else    return (RXERR_INVALID_ARG);
  124.     }
  125.  
  126.     if ( cf_Write (Header, Mode, &Error) )
  127.             *ResStr = SetRC_TRUE ();
  128.     else    SetErrVar (RxMsg, ERRFUNC_WRITE, Error);
  129.  
  130.     return (RC_OK);
  131. }
  132.